//
//  Team9RenovateTableViewCell.m
//  Team9Project
//
//  Created by 朱嘉祺 on 15/10/12.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "Team9RenovateTableViewCell.h"
#import <Masonry.h>
#import <UIImageView+WebCache.h>
#import "Team9RenovateModel.h"
#import "Team9renovateViewController.h"
@implementation Team9RenovateTableViewCell



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatAllView];
    }
    return self;
}


- (void)setRenovateModel:(Team9RenovateModel *)renovateModel{

    if (_renovateModel != renovateModel) {
        
        _renovateModel = renovateModel;
        
        
        
        
    }

    if (![_renovateModel.col_name isEqualToString:@"梦幻"]) {
       
   

    
    // 头像
    [Team9Tool sd_imageView:_headImageView image:_renovateModel.author_face placeholder:[UIImage imageNamed:@"333"]];

    
    
    // 名字
    self.titleLabel.text = _renovateModel.col_name;
    
    // 点赞
    self.likeImageView.image = [UIImage imageNamed:@"like"];
    self.likeLabel.text = _renovateModel.liked_count;
    
    // 图片
    if (_renovateModel.diary_pics != nil) {
        if (_renovateModel.diary_pics.count == 1) {
            
            [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:_renovateModel.diary_pics[0][@"pic"]] placeholderImage:[UIImage imageNamed:@"111"] options:SDWebImageRetryFailed];
            
        }else if(_renovateModel.diary_pics.count == 2){
            
            [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:_renovateModel.diary_pics[0][@"pic"]] placeholderImage:[UIImage imageNamed:@"111"] options:SDWebImageRetryFailed];
            [self.centerImageView sd_setImageWithURL:[NSURL URLWithString:_renovateModel.diary_pics[1][@"pic"]] placeholderImage:[UIImage imageNamed:@"111"] options:SDWebImageRetryFailed];
            
        }else if(_renovateModel.diary_pics.count == 3){
            
            [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:_renovateModel.diary_pics[0][@"pic"]] placeholderImage:[UIImage imageNamed:@"111"] options:SDWebImageRetryFailed];
            [self.centerImageView sd_setImageWithURL:[NSURL URLWithString:_renovateModel.diary_pics[1][@"pic"]] placeholderImage:[UIImage imageNamed:@"111"] options:SDWebImageRetryFailed];
            [self.rightImageView sd_setImageWithURL:[NSURL URLWithString:_renovateModel.diary_pics[2][@"pic"]] placeholderImage:[UIImage imageNamed:@"111"] options:SDWebImageRetryFailed];
    
        }
        
        if (_renovateModel.diary_pics.count == 0) {
            [self.leftImageView setHidden:YES];
            [self.centerImageView setHidden:YES];
            [self.rightImageView setHidden:YES];
        } else {
            [self.leftImageView setHidden:NO];
            [self.centerImageView setHidden:NO];
            [self.rightImageView setHidden:NO];
        }
        
   
//        [Team9Tool imageView:_headImageView type:@"0" Id:_renovateModel.author_id viewController:self.vc baiHiden:YES];
        
        [Team9Tool imageView:_headImageView Id:_renovateModel.author_id viewController:self.vc barHiden:YES];
   

}
    
    // 状态
    self.stateLabel.text = _renovateModel.diary_content;
    // 类型
    self.typeLabel.text = [NSString stringWithFormat:@"装修进度: %@", _renovateModel.section_name] ;

    }

}

-(void)creatAllView
{
    
    // 背景
    self.backView = [[Team9BaseView alloc] initWithType:ViewTypeWhiteBlack];
    [self.contentView addSubview:self.backView];
    self.backView.layer.cornerRadius = 5 / 375.0 * WIDTH;
    self.contentView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
   
    
    // 头像
    self.headImageView = [[UIImageView alloc] init];
    [self.backView addSubview:self.headImageView];
    self.headImageView.layer.masksToBounds = YES;
    self.headImageView.backgroundColor = [UIColor clearColor];
    self.headImageView.layer.cornerRadius = 20 / 375.0 * WIDTH ;
    
    // 标题
    self.titleLabel = [[Team9BaseLabel alloc] initWith:LableColorTypeOrangeGreen];
    self.titleLabel.font = [UIFont systemFontOfSize:15 / 375.0 * WIDTH];
    [self.backView addSubview:self.titleLabel];

    
   
    
    // 图片
    self.leftImageView = [[UIImageView alloc] init];
    [self.backView addSubview:self.leftImageView];
    
    self.centerImageView = [[UIImageView alloc] init];
    [self.backView addSubview:self.centerImageView];
    
    self.rightImageView = [[UIImageView alloc] init];
    [self.backView addSubview:self.rightImageView];
    
    // 点赞
    self.likeImageView = [[UIImageView alloc] init];
    [self.backView addSubview:self.likeImageView];
    
    self.likeLabel = [[Team9BaseLabel alloc] initWith:LableColorTypeBlackWhite];
    [self.backView addSubview:self.likeLabel];
    self.likeLabel.textAlignment = NSTextAlignmentCenter;
    self.likeLabel.font = [UIFont systemFontOfSize:10 / 375.0 * WIDTH];
    
    
    // 状态
    self.stateLabel = [[Team9BaseLabel alloc] initWith:LableColorTypeBlackWhite];
    [self.backView addSubview:self.stateLabel];
    self.stateLabel.numberOfLines = 0;
    [self.stateLabel sizeToFit];
//    self.stateLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
    self.stateLabel.font = [UIFont systemFontOfSize:13 / 375.0 * WIDTH];
    
    // 类型
    self.typeLabel = [[Team9BaseLabel alloc] initWith:LableColorTypeBlackWhite];
    [self.backView addSubview:self.typeLabel];
    self.typeLabel.font = [UIFont systemFontOfSize:13 / 375.0 * WIDTH];
    
    
   
    
}






-(void)layoutSubviews
{
     [super layoutSubviews];
    
    // 背景
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(10 / 375.0 * WIDTH, 10 / 375.0 * WIDTH, 10 / 375.0 * WIDTH, 10 / 375.0 * WIDTH));
    }];
    
    
    
    // 头像
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.backView.mas_top).offset(10 / 375.0 * WIDTH);
        make.left.equalTo(self.backView.mas_left).offset(10 / 375.0 * WIDTH);
        make.width.equalTo(self.headImageView.mas_height);
        make.width.equalTo(self.backView.mas_width).multipliedBy(0.11);
        
        
    }];
    
    // 题目
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.backView.mas_top).offset(12 / 375.0 * WIDTH);
        make.left.equalTo(self.headImageView.mas_right).offset(10 / 375.0 * WIDTH);
        make.width.equalTo(self.titleLabel.mas_height).multipliedBy(9.3);
        make.width.equalTo(self.backView.mas_width).multipliedBy(0.65);
        
    }];
    
    if (self.renovateModel.diary_pics.count) {
        // 图片
       
        [self.leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.backView.mas_left).offset(10 / 375.0 * WIDTH);
            make.top.equalTo(self.headImageView.mas_bottom).offset(12 / 375.0 * WIDTH);
            make.width.equalTo(self.leftImageView.mas_height);
            
            
            
        }];
        
        [self.centerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.leftImageView.mas_right).offset(10 / 375.0 * WIDTH);
            make.centerY.equalTo(self.leftImageView);
            make.size.equalTo(self.leftImageView);
            
            
        }];
        
        [self.rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.centerImageView.mas_right).offset(10 / 375.0 * WIDTH);
            make.centerY.equalTo(self.leftImageView);
            make.right.equalTo(self.backView.mas_right).offset(-10 / 375.0 * WIDTH);
            make.size.equalTo(self.leftImageView);
            
        }];

    }
    
    
    
    
    // 点赞
    [self.likeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headImageView.mas_top).offset(6 / 375.0 * WIDTH);
        make.left.equalTo(self.titleLabel.mas_right).offset(35 / 375.0 * WIDTH);
        make.right.equalTo(self.backView.mas_right).offset(-10 / 375.0 * WIDTH);
        make.width.equalTo(self.likeImageView.mas_height);
        
    }];
    
    [self.likeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.likeImageView.mas_bottom);
        make.left.equalTo(self.titleLabel.mas_right).offset(35 / 375.0 * WIDTH);
        make.right.equalTo(self.backView.mas_right).offset(-10 / 375.0 * WIDTH);
        make.width.equalTo(self.likeLabel.mas_height).multipliedBy(1.2);
        
    }];
    
    // 状态（自适应）
    if (self.renovateModel.diary_pics.count == 0) {
        [self.stateLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(self.contentView).offset(100 / 375.0 * WIDTH);
            make.left.equalTo(self.backView.mas_left).offset(10 / 375.0 * WIDTH);
            make.right.equalTo(self.backView.mas_right).offset(-10 / 375.0 * WIDTH);
//            make.width.equalTo(self.backView.mas_width).offset(-20 / 375.0 * WIDTH).priorityLow();
//
        }];
        
    }else{
        [self.stateLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(185 / 375.0 * WIDTH);
            make.left.equalTo(self.backView.mas_left).offset(10 / 375.0 * WIDTH);
            make.right.equalTo(self.backView.mas_right).offset(-10 / 375.0 * WIDTH);
//            make.width.equalTo(self.backView.mas_width).offset(-20 / 375.0 * WIDTH).priorityLow();
          
            
        }];
    
    }
    
    
    
    // 类型
    [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(1 / 375.0 * WIDTH);
        make.left.equalTo(self.headImageView.mas_right).offset(10 / 375.0 * WIDTH);
        make.width.equalTo(self.typeLabel.mas_height).multipliedBy(9.3);
        make.width.equalTo(self.backView.mas_width).multipliedBy(0.5);
        
    }];

    
}









- (void)awakeFromNib {
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

 }

@end
